function Resource(){
  this.name = null;
  this.uri = null;
  this.href = null;
  this.entities = new Array();
};

Resource.prototype.parseXml = function(xmlStr){
  var resource = new Resource();
  var xmlReader = Components.classes["@mozilla.org/saxparser/xmlreader;1"]
                          .createInstance(Components.interfaces.nsISAXXMLReader);
  xmlReader.contentHandler = {
    currentElement: null,
    tmpEntity : null,

    startDocument: function() {},
		endDocument: function() {},

    startElement: function(uri, localName, qName, /*nsISAXAttributes*/ attributes) {
      this.currentElement = qName;
      //debug("[startElement] currentElement:" + this.currentElement ,1);

      if(qName == "resource"){
        for(var i=0; i<attributes.length; i++) {
          if(attributes.getQName(i) == "name")
            resource.name = attributes.getValue(i);
          if(attributes.getQName(i) == "href")
            resource.href = attributes.getValue(i);
        }
      }

      if(qName == "entity"){
        this.tmpEntity = {};
        this.tmpEntity.name = "";
        for(var i=0; i<attributes.length; i++)
          if(attributes.getQName(i) == "href")
            this.tmpEntity.href = attributes.getValue(i);
      }
    },

    endElement: function(uri, localName, qName) {
      if(this.currentElement == "entity" && this.tmpEntity != null){
        resource.entities.push(this.tmpEntity);
        this.tmpEntity = null;
      }
      this.currentElement = null;
    },

    characters: function(value) {
      if((typeof this.currentElement) != "string")
        return;
      if(this.currentElement == "entity"){
        this.tmpEntity.name = value;
      }
    },
    processingInstruction: function(target, data) {},
    ignorableWhitespace: function(whitespace) {},
    startPrefixMapping: function(prefix, uri) {},
    endPrefixMapping: function(prefix) {},

    // nsISupports
    QueryInterface: function(iid) {
      if(!iid.equals(Components.interfaces.nsISupports) &&
         !iid.equals(Components.interfaces.nsISAXContentHandler))
        throw Components.results.NS_ERROR_NO_INTERFACE;
      return this;
    }
  }
  xmlReader.parseFromString(xmlStr, "text/xml");
  return resource;
}

Resource.prototype.httpGet = function(user, pass) {
	if(this.uri == null){
		return null;
	}
	var req = new customRequest('GET', this.uri, "");
	var http = new HTTPCore();
	if(typeof user == "string" && user != "")
	  http.auth(user, pass);
	var res = http.doOperation(req);
	debug("[entity.js::httpGet] Entity.httpGet URL:" + this.uri, 1);
	debug("[entity.js::httpGet] Entity.httpGet Response:" + http.response, 1);
	if(!res) return false;
	var res = this.parseXml(http.response);
	return res;
}